package com.xhm.spring.dao;

import com.xhm.spring.model.User;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List;

/**
 * Created by coolxu on 2017/11/7....
 */
@Repository("jdbcUserDao")
public class UserDao implements IUserDao {

	private JdbcTemplate jdbcTemplate;


	@Resource
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	@Override
	public void add(User user) {
		this.jdbcTemplate.update(
				"insert into t_user (username, password,nickname) values (?,?,?)",
				user.getUsername(), user.getPassword(), user.getNickname());

	}

	@Override
	public void update(User user) {
		this.jdbcTemplate.update(
				"update t_user set username = ?,password=?,nickname=?  where id = ?",
				user.getUsername(), user.getPassword(), user.getNickname(), user.getId());

	}

	@Override
	public void delete(int id) {
		this.jdbcTemplate.update("delete from t_user where id = ?", id);
	}

	@Override
	public User load(int id) {

		return null;
	}

	@Override
	public List<User> list() {

		return null;
	}


}
